<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
%>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<!doctype html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="copyright" content=""/>
    <meta name="keywords" content=""/>
    <meta name="description" content=""/>
	<title>设置-修改资料</title>
	<link href="https://cdn.jsdelivr.net/gh/bootcdn/BootCDN/ajax/libs/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
	<link href="${pageContext.request.contextPath}/css/system/public.css" />
	<link href="${pageContext.request.contextPath}/css/system/set.css" rel="stylesheet">
	<link href="${pageContext.request.contextPath}/css/system/alert.css" rel="stylesheet">
	<link href="../favicon.ico" rel="shortcut icon">
	<link href="<%=path%>/hplus/css/bootstrap.min14ed.css?v=3.3.6" rel="stylesheet">
	<link href="<%=path%>/hplus/css/font-awesome.min93e3.css?v=4.4.0" rel="stylesheet">
	<link href="<%=path%>/hplus/css/plugins/iCheck/custom.css" rel="stylesheet">
	<link href="<%=path%>/hplus/css/animate.min.css" rel="stylesheet">
	<link href="<%=path%>/hplus/css/style.min862f.css?v=4.1.0" rel="stylesheet">
</head>
<body class="gray-bg">
   <div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
           <div class="s_basics col-md-12">
                <ul class="s_basics_list form">
                    <b class="ok_btn"><a href="javascript:;" id="endEdit">完成</a></b>
                    <li class="k_ban"><span>公司</span><input type="text" placeholder="" id="c_name" readonly="readonly" style="color:gray"/></li>
                    <li class="k_ban"><span>地区</span><input type="text" placeholder="" id="cityTextBtn" readonly="readonly" style="color:gray"/></li>
                    <li class="k_ban"><span>行业</span><input type="text" placeholder="" id="industryTextBtn" readonly="readonly" style="color:gray" /></li> 
                  <!--   <div class="posR">
                        <p class="s_dropdown_p">
                            地区
                        </p>
                        <div class="dropdown s_dropdown">
                            <button class="btn btn-default dropdown-toggle tL" type="button">     
                                <em class="cityTextBtn">请选择</em>
                                <span class="dropImg"><img src="${pageContext.request.contextPath}/images/system/dropDown.png"/></span>
                            </button>
                            <div class="dropdown-menu dropdownLeft">
                                <ul class="pro">
                                </ul>
                            </div>
                            <div class="dropdown-menu dropdownRight">
                                <ul class="city">
                                </ul>
                            </div>
                        </div>
                        <input type="hidden" class="cityTextVal" value=""/>
                    </div>
                    <div class="posR">
                        <p class="s_dropdown_p">
                            行业
                        </p>
                        <div class="dropdown s_dropdown">
                            <button class="btn btn-default dropdown-toggle tL" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
                            <em class="industryTextBtn" >请选择</em>
                            <span class="dropImg"><img src="${pageContext.request.contextPath}/images/system/dropDown.png"/></span>
                            </button>
                            <div class="dropdown-menu dropdownLeft industry">
                                <ul class="parentOption">
                                </ul>
                            </div>
                            <div class="dropdown-menu dropdownRight industryChild">
                                <ul class="childOption">机构及其他
                                </ul>
                            </div>
                        </div>
                        <input type="hidden" class="industryTextVal" value=""/>
                    </div> -->
                    <li><span>座机</span><input type="text" placeholder="请输入座机号码" id="c_phone" maxlength="20" onkeyup="this.value=this.value.replace(/[^0-9|^-]/g,'')"  onafterpaste="this.value=this.value.replace(/[^0-9|^-]/g,'')"/><font style="margin-left: 15px" id="err" color="red"></font></li>
                    <li><span>企业介绍</span><textarea rows="4" id="c_intro" maxlength="1000"></textarea></li>
                    <li><span>企业业务</span><input type="text" style="width:40%;" placeholder="多业务请使用“，”分开" id="c_business"/>
                        <em>例如：童装，OA，百度推广，机票，旅游等</em></li>
                    <li>
                        <span>企业营业执照</span>
                        <em id="scxs"></em>
                        <button class="uploadBtn" style="margin-left: 10px">上传
                        <input onchange="previewImage(this)" type="file" class="uploadFile" id="uploadFile" name="file"/></button>
                        <!-- <a href="javascript:;" class="s_charter" id="s_charter"></a>
                        <a href="javascript:;" class="s_delect_btn" id="s_delect_btn">删除</a> -->
                    </li>
                    <!-- <li>
                        <span>行业关键字</span>
                        <div class="form s_keyword">
                            <input type="text" placeholder="请输入关键字" id="i"/>
                            <span id = "s">Enter确认</span>
                            <em id = "e" >已输入5个关键字，还可输入0个</em>
                        </div>
                        <br />
                        <div class="key fix" id="kf">
                            关键字
                        </div>
                    </li>  -->
                </ul>
            </div>
    </div>
   </div>
    <!-- 企业营业执照预览 -->
     <div class="k_popup">
        <div class="k_issues">
            <div id="preview">
            	<img src="${pageContext.request.contextPath}/images/system/del.png" id="datu"/>
            </div>
            <span>
            	<img src="${pageContext.request.contextPath}/images/system/icon_close.png" />
            </span>            
        </div>
    </div> 
<div class="s_popup_delect2">
        <div class="s_consum">
            <p id="dialog_title"><img src="${pageContext.request.contextPath}/images/system/s_tick.png" /></p>
        </div>
    </div>
 	<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
    <script type="text/javascript" src="../sys/set/bootstarp/js/upload.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/system/exit.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/system/jquery.ui.widget.js"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath}/js/system/jquery.iframe-transport.js"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath}/js/system/jquery.fileupload.js"></script>	
    <script>

        $('.s_keyword input').on('keydown',function(e){
            $(this).parents('.s_keyword').find('span').show();
            if(e.keyCode==13){
                var keyword = $.trim($('.s_keyword input').val());
                var html = "";
                var len = $('.key>div').length;

                var newLen = $('.key>div').length;
                if(len>4){
                    $('.s_keyword input').hide();
                    $('.s_keyword em').show();
                }
                if(!keyword==""){
                    if(len>=5){
                        return false;
                    }
                    if(keyword.indexOf(',') != -1 || keyword.indexOf('，') != -1 || keyword.indexOf('、') != -1){
						showDialog("不能添加逗号、顿号");
						$('.s_keyword input').val('');
						return false;
                    }
                    html = "<div><div>"+keyword+"<img class='del' src='${pageContext.request.contextPath}/images/system/del-1.png'/></div></div>"
                }
                /*判断关键字不能相同   start*/
                var kfs = $('#kf').children(); 
                var fflag = true;
                kfs.each(function(){
					var cf = $(this).text();
						if(cf == keyword){
							fflag = false;
							return ;
						}
				}); 
                 if(fflag){
                	 	$('.key').append(html);
						$('.s_keyword input').val('');
		                $(this).parents('.s_keyword').find('span').hide()
                 }else{
                	 	showDialog("不能重复添加相同的关键字");
						$('.s_keyword input').val('');
                 }
                 len = $('.key>div').length;
                 if(len>4){
                     $('.s_keyword input').hide();
                     $('.s_keyword em').show();
                 }
            }
        });

        $('body').on('click','.del',function(){
            $('.form input').show();
            $('.s_keyword em').hide();
            $(this).parent().parent().remove();
        });

        /* $('#scxs').click(function(){
            $('.k_popup').show();
            $('.k_issues').show();
        }); */
        $(document).on('click','.xian',function(){
        	$('.k_popup').show();
            $('.k_issues').show();
        });
        $('.k_issues span').click(function(){
            $('.k_popup').hide();
            $('.k_issues').hide();
        });
        $(function(){
            $('.k_issues span').on('click',function(){
                $('.k_popup').hide();
            })
            $('.s_delect_btn').on('click',function(){
                $('#preview').html('');
                $('#s_charter').text("");
                $("#s_delect_btn").hide();
            })
        });
                $(function(){
            var cityJSON = null;
            var cityText = "";
            var industryJson = null;
            var optionText = "";
            var itemNum = 0;
            $.getJSON("${pageContext.request.contextPath}/js/system/industry.js",function(result){
                industryJson = result["industry"];
                var industry = "";
                $.each(industryJson,function(i,item){
                    industry+="<li><a href='javascript:void(0);'>"+item['p']+"<input class='industryIndex' type='hidden' value='"+i+"'/></a></li>";
                    console.log(industry);
                    $('.parentOption').html(industry)
                });
                $.getJSON("${pageContext.request.contextPath}/js/system/city.js",function(result){
                    cityJSON = result["citylist"];
                    var pro = "";
                    $.each(cityJSON,function(i,item){
                        pro+="<li><a href='javascript:void(0);'>"+item['p']+"<input class='proIndex' type='hidden' value='"+i+"'/></a></li>";
                    })
                    $('.pro').html(pro)
                });
                var proIndex = null;
                $('.pro').on('mouseenter','li',function(e){
                    e.stopPropagation();
                    proIndex = $(this).find('.proIndex').val();

                    console.log(proIndex)
                    if(Number(proIndex)!=0 && Number(proIndex)!=1 && Number(proIndex)!=8 && Number(proIndex)!=21){
                        cityText = $(this).find('a').text()+"省";
                    }else{
                        cityText = $(this).find('a').text()+"市";
                    }
                    $(this).find('a').addClass('on').parent().siblings().find('a').removeClass('on');
                    var city = cityJSON[proIndex]["c"];
                    var cityHTML = "";
                    $.each(city,function(i,item){
                        cityHTML+="<li><a href='javascript:void(0);'>"+item['n']+"<input class='cityIndex' type='hidden' value='"+i+"'/></a></li>";
                    })
                    $('.city').html(cityHTML);
                    $(this).parents('.s_dropdown').find('.dropdownRight').show();
                });


                var industryIndex = null;
                $('.parentOption').on('click','li',function(e){
                    var industryText = "";
                    optionText="";
                    e.stopPropagation();
                    optionText+=$(this).find('a').text()+"-";
                    industryIndex = $(this).find('.industryIndex').val();
                    $(this).find('a').addClass('on').parent().siblings().find('a').removeClass('on');
                    var industrys = industryJson[industryIndex]["c"];
                    var industryHTML = "";
                    $.each(industrys,function(i,item){
                        industryHTML+="<li><a href='javascript:void(0);'>"+item['n']+"<input class='cityIndex' type='hidden' value='"+i+"'/></a></li>";
                    })
                    $('.childOption').html(industryHTML);
                    $(this).parents('.s_dropdown').find('.dropdownRight').show();
                });

                $('.childOption').on('click','li',function(e){
                    e.stopPropagation();
                    industryText=$(this).find('a').text();
                    optionText+=$(this).find('a').text();

                    $(this).parents('.s_dropdown').find('.dropdown-menu').hide();

                    $('.industryTextBtn').text(industryText);
                    $('.industryTextVal').val(optionText);
                    cityText = "";
                    $('.dropdown-toggle').removeClass('btnOn');
                });

                $('.city').on('click','li',function(e){
                    e.stopPropagation();
                    console.log(proIndex)
                    if(Number(proIndex)!=0 && Number(proIndex)!=1 && Number(proIndex)!=8 && Number(proIndex)!=21 && Number(proIndex)!=33){
                        cityText+=$(this).find('a').text()+"市";
                    }else{
                        cityText += $(this).find('a').text();
                    }

                    $(this).parents('.s_dropdown').find('.dropdown-menu').hide();
                    $('.cityTextBtn').text(cityText);
                    $('.cityTextVal').val(cityText);
                    $('.cityText').show();
                    cityText = "";
                    $('.dropdown-toggle').removeClass('btnOn');
                });
                $('.dropdown-toggle').on('click',function(e){
                    e.stopPropagation();
                    $('.dropdown-menu').hide();
                    $(this).toggleClass('btnOn');
                    if($(this).hasClass('btnOn')){
                        $(this).next().show();
                    }else{
                        $(this).parent().find('.dropdown-menu').hide();
                    }
                });

                $('body').on('click',function(){
                    $('.dropdown-menu').hide();
                    $('.dropdown-toggle').removeClass('btnOn');
                });

                $('.s_fx_li1').click(function(){
                  var id = $(this).find('img').attr('_id');
                    if(id == 1){
                      $('.s_fk_pic1').attr('src', '${pageContext.request.contextPath}/images/system/s_check_no.png');
                      $(this).find('img').attr('_id' , '2');
                    }else{
                      $('.s_fk_pic1').attr('src', '${pageContext.request.contextPath}/images/system/s_check.png');
                      $(this).find('img').attr('_id' , '1');
                    }
                });
                $('.s_fx_li2').click(function(){
                  var id = $(this).find('img').attr('_id');
                    if(id == 3){
                      $('.s_fk_pic2').attr('src', '${pageContext.request.contextPath}/images/system/s_check_no.png');
                      $(this).find('img').attr('_id' , '4');
                    }else{
                      $('.s_fk_pic2').attr('src', '${pageContext.request.contextPath}/images/system/s_check.png');
                      $(this).find('img').attr('_id' , '3');
                    }
                });
                $('.s_fx_li3').click(function(){
                  var id = $(this).find('img').attr('_id');
                    if(id == 5){
                      $('.s_fk_pic3').attr('src', '${pageContext.request.contextPath}/images/system/s_check_no.png');
                      $(this).find('img').attr('_id' , '6');
                    }else{
                      $('.s_fk_pic3').attr('src', '${pageContext.request.contextPath}/images/system/s_check.png');
                      $(this).find('img').attr('_id' , '5');
                    }
                });
                $('.s_fx_li4').click(function(){
                  var id = $(this).find('img').attr('_id');
                    if(id == 7){
                      $('.s_fk_pic4').attr('src', '${pageContext.request.contextPath}/images/system/s_check_no.png');
                      $(this).find('img').attr('_id' , '8');
                    }else{
                      $('.s_fk_pic4').attr('src', '${pageContext.request.contextPath}/images/system/s_check.png');
                      $(this).find('img').attr('_id' , '7');
                    }
                });
                $('.s_fx_li5').click(function(){
                  var id = $(this).find('img').attr('_id');
                    if(id == 9){
                      $('.s_fk_pic5').attr('src', '${pageContext.request.contextPath}/images/system/s_check_no.png');
                      $(this).find('img').attr('_id' , '10');
                    }else{
                      $('.s_fk_pic5').attr('src', '${pageContext.request.contextPath}/images/system/s_check.png');
                      $(this).find('img').attr('_id' , '9');
                    }
                });
            })
            $('.addEle').on('keydown',function(e){
                var ele = "";
                if(e.keyCode==13){
                    var con = $.trim($(this).val());
                    if(con==""){
                        $(this).val('');
                        return false;
                    }
                    if(itemNum>=3){
                        return false;
                    }
                    itemNum++;
                    if(itemNum==3){
                        $('.addEle').css('visibility','hidden');
                        $('.showDialogWord').css('visibility','hidden');
                    }
                    ele = '<li class="s_fx_li1 c_li"><img src="${pageContext.request.contextPath}/images/system/s_check.png" class="c_'+itemNum+'" _id="c_'+itemNum+'" />'+con+' <img class="k_del" src="images/k_close.png" /></li>';
                    $('.s_login_box ol').append(ele);
                    $(this).val('');
                }
            })
            $('body').on('click','.k_del',function(){
                $(this).parent().remove();
                $('.addEle').css('visibility','visible');
                $('.showDialogWord').css('visibility','visible');
                itemNum--;
            })
        })
       
    </script>
        <!-- LeeX -->
    <script type="text/javascript">
    $(function(){
		$.post("<%=path%>/api/company/show",function(data){
			if(data.error_code == "20028"){
				showDialog(" 账户已被登陆，请重新登陆。");
				setTimeout('window.location.href="http://scrm.cecook.cn/"',2000);
			}
			/* 公司名称 */
			var c_name = data.name;
			if(c_name==null){
				$('#c_name').val("");
			}else{
				$('#c_name').val(data.name);
			}
			/* 地区 */
			var c_city = data.city;
			if(c_name==null){
				$('#cityTextBtn').val("");
			}else{
				$('#cityTextBtn').val(data.city);
			}
			/* 行业 */
			var c_industry = data.industry;
			if(c_industry==null){
				$('#industryTextBtn').val("");
			}else{
				$('#industryTextBtn').val(data.industry);
			}
			/* 企业介绍 */
			var c_intro = data.intro;
			if(c_intro==null){
				$('#c_intro').val("");
			}else{
				$('#c_intro').val(data.intro);
			}
			/* 企业介绍 */
			var c_phone = data.phone;
			if(c_phone==null){
				$('#c_phone').val("");
			}else{
				$('#c_phone').val(data.phone);
			}
			/* 企业行业 */
			var c_business = data.business;
			if(c_business==null){
				$('#c_business').val("");
			}else{
				$('#c_business').val(data.business);
			}
			/* 营业执照 */
			var b_license = data.b_license;
			if(b_license==null){
				$('#scxs').html("未上传");
			}else{
				$('#scxs').html('<img src="'+b_license+'" class="xian" width="192px" height="119px">');
				$('#datu').attr("src",b_license);
				/* var strs = b_license.split("/");
				 for(var i = 0 ; i < strs.length ;i++){
					if(i == strs.length - 1){
	    				$('.s_charter').text(strs[i]);
					}
				}  */
			}
			/* 关键字 */
			/* var kw = data.keyword;
			var arr = kw.split(",");
			if(arr[0] != ""){
				for(var i = 0 ; i < arr.length;i++){
					$('#kf').append('<div><div>'+arr[i]+'<img class="del" src="${pageContext.request.contextPath}/images/system/del-1.png"/></div></div>');
				}
			} */
			
			kfl = "y";
			doch();
		});
	
	
		
		$('#endEdit').click(function(){
			/* 名称 */
			/* var e_name = $('#c_name').val(); */
			/* 地区 */
			/* var e_city = $('#cityTextBtn').val(); */
			/* 行业 */
			/* var e_industry = $('#industryTextBtn').val(); */
			if(!checkCPhone()){
				return;
			}
			/* 电话 */
			var e_phone = $('#c_phone').val();
			/* 介绍 */
			var e_intro = $('#c_intro').val();
			/* 业务 */
			var e_business = $('#c_business').val();
			/* 关键字 */
			/* 获取第一层div  遍历 */
			/* var kfs = $('#kf').children();
			var keyword ="";
			for(var i = 0 ; i < kfs.length ; i++){
				var k = kfs[i];
				if(i == kfs.length - 1 ){
					keyword += $(k).children().text();
				}else{
					keyword += $(k).children().text()+",";
				}
			} */
			var url = "<%=path%>/api/company/update";
			var params = {
					"phone":e_phone,
					"intro":e_intro,
					"business":e_business
				};
			/* 发送请求 */
			$.post(url,params,function(data){
				if(data.error_code == "20028"){
					showDialog(" 账户已被登陆，请重新登陆。");
					setTimeout('window.location.href="http://scrm.cecook.cn/"',2000);
				}
				if("0" == data.error_code){
					showDialog("修改成功");
					window.location.href = "<%=path%>/ui/companyInfoShow";
				}else{
					showDialog(data.message);
					window.location.href = "<%=path%>/ui/companyInfoShow";
				}
			});
		});
    });
	
    </script>
<script type="text/javascript">
$(function(){
	$(":file").click(function(){
		$('.uploadFile').fileupload({
			url : "${pageContext.request.contextPath}/api/company/uploadBLicense",
			iframe: true,
			dataType:"json",
			done : function(e,data) {
				if("10010"==data.result.error_code){
					showDialog(data.result.error_msg);	
				}else{
					$('#scxs').html('<img src="'+data.result.b_license+'" class="xian" width="192px" height="119px">');
					$('#datu').attr('src',data.result.b_license);
					showDialog("上传成功");
				}
			},

		});
	});
	
	$('.s_delect_btn').click(function(){
		$.post(
				"${pageContext.request.contextPath}/api/company/delBLicense",
				{},
				function(data){
					if(data.error_code == "20028"){
						showDialog(" 账户已被登陆，请重新登陆。");
						setTimeout('window.location.href="http://scrm.cecook.cn/"',2000);
					}
					if(data.error_code == "10010"){
						showDialog(data.message);
					}
		},'json');
	});
});
</script>
<script type="text/javascript">
	var kfl ;
	function doch(){
		if(kfl == "y"){
			var kfss = $('#kf').children();
			if(kfss.length == 5){
				$('#i,#s').hide();
				$('#e').show();
			}
		}
	}
	
	function checkCPhone(){
		var c_phone = $('#c_phone').val();
		if(c_phone == null || c_phone ==""){
			return true;
		}
		var reg = /^((0|[2-9])[0-9]{2,3})?(\-)?([2-9][0-9]{3,7})+(\-)?([0-9]{0,8})?$/;
		if(!reg.test(c_phone)){
			$('#err').text("固定电话格式不正确，例：010-22345678 或 01022345678");
			return false;
		}else{
			return true;
		}
	}
	
	$('#c_phone').focus(function(){
		$('#err').text("");
	});
</script>
<script type="text/javascript">
var auths = "<%=session.getAttribute("authoritys")%>";
</script>
</body>
</html>